##train_log

log<-read.table("training_log.txt",sep = ",",header = T)

plot(log$Iters,log$Loss,col = "blue",lwd = 2,type="l",xlab="iterations",ylab="Loss")

plot(log$Iters,log$Acc.1,col = "blue",add=T, lwd = 2,type="l",xlab="iterations",ylab="Acc")
lines(log$Iters, log$Loss, col = "red", lwd = 2, type = "l")


library(ggplot2)
library(gridExtra)
log <- read.table("training_log.txt", sep = ",", header = TRUE)

# 创建第一个绘图层，截断Y轴
plot1 <- ggplot(log, aes(Iters, Loss)) +
  geom_line(colour = "blue", size = 1) +
  coord_cartesian(ylim = c(0, 1)) +
  labs(x = "iterations", y = "Loss")+theme(plot.title = element_text(hjust = 0.5), 
                                           # legend.justification=c(1, 0), legend.position=c(.95, .05),
                                           legend.title=element_blank(), 
                                           panel.grid = element_blank())

# 创建第二个绘图层，拼接Y轴
plot2 <- ggplot(log, aes(Iters, Acc.1)) +
  geom_line(colour = "red", size = 1) +
  coord_cartesian(ylim = c(60, 100)) +
  labs(x = "iterations", y = "Acc")+theme(plot.title = element_text(hjust = 0.5), 
                                          # legend.justification=c(1, 0), legend.position=c(.95, .05),
                                          legend.title=element_blank(), 
                                          panel.grid = element_blank())

# 拼接两个绘图层
plot_combined <- grid.arrange(plot1, plot2, nrow = 2)

# 显示融合后的图像
print(plot_combined)
